package lgkj.meicqt20.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import lgkj.meicqt20.R;
import lgkj.meicqt20.bean.VideosEntity;
import lgkj.meicqt20.utils.CommUtils;

/**
 * Created by Administrator on 2017/8/11 0011.
 */

public class VideoListAdapter extends BaseAdapter {
    private List<VideosEntity.DataBean> data;
    private Context context;
    private int position = -1;
    private boolean isShow = true;

    public void setShow(boolean show) {
        isShow = show;
    }

    public boolean isShow() {
        return isShow;
    }

    public void setPosition(int position) {
        this.position = position;
    }


    public VideoListAdapter(Context context) {
        this.context = context;
        data = new ArrayList<>();
    }

    public void setData(List<VideosEntity.DataBean> data) {
        if (data != null) {
            this.data = data;
        } else {
            this.data.clear();
        }
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public VideosEntity.DataBean getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder = null;
        if (view == null) {
            viewHolder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.item_vidoe, null);
            viewHolder.fl_select = view.findViewById(R.id.fl_select);
            viewHolder.video_one = view.findViewById(R.id.video_one);
            viewHolder.video_pic = view.findViewById(R.id.video_pic);
            viewHolder.video_name = view.findViewById(R.id.video_name);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.video_name.setText(data.get(i).getVideo_name());
        CommUtils.LoadImage(context, viewHolder.video_pic, data.get(i).getVideo_img(), R.drawable.common_icon_err);
        Log.i("1111", "getView: " + data.get(i).toString());
        if (position == i) {
            if (isShow) {
                viewHolder.video_one.setBackgroundResource(R.drawable.yxzxyxbk);
            } else {
                viewHolder.video_one.setBackgroundResource(0);
            }

        } else {
            viewHolder.video_one.setBackgroundResource(0);
        }
        return view;
    }

    class ViewHolder {
        FrameLayout fl_select;
        ImageView video_one;
        ImageView video_pic;
        TextView video_name;
    }
}
